/**
 * 虚拟钱包充血模型
 */
public class VirtualWallet {
    private Long id;
    private Long createTime = System.currentTimeMillis();
    private BigDecimal balance;

    public VirtualWallet(Long id) {
        //这里可以改为雪花算法生成
        this.id = id;
    }

    /**
     * 查询余额
     */
    public Long getBalance() {
        return balance;
    }

    /**
     * 出账
     *
     * @param amount
     */
    public void debit(BigDecimal amount) {
        if (this.balance.compareTo(amount) < 0) {
            throw new Exception();
        }
        this.balance.subtract(amount);
    }

    /**
     * 入账
     */
    public void credit(BigDecimal amount) {
        if (amount.compareTo(BigDecimal.Zero) < 0) {
            throw new Exception();
        }
        this.balance.add(amount);
    }

}